/**
 * spring board 调查列表. 
 */
var surveyList = (function(){   
     
    var linkCardTmp = [
        '<div class="cardWrapper" card-id="<%=o.id%>" lastDoTime="<%=o.lastDoTime%>">',
            '<div class="cardCtn">',
                '<div class="cardIcon">',
                    '<a href="<%=o.url%>" target="_blank">',
                        '<img class="cardIconImg" src="<%=o.icon%>" onerror=this.src="{0}" />'.format(ujs.getConfigRes('emptyImagePath')),
                    '</a>',                    
                '</div>',
                '<div class="cardName breakWord ellipsis" style="text-align: center;margin-top: 6px;" title="<%=name%>" ><%=name%></div>',
            '</div>',
            // '<div class="cardToolbar">',
                // '<button class="cardToolbarItem edit" style="<%=o.perm && !o.perm.upd ? "display:none" : "" %>" >',
                    // '<img title="Edit" src="/ujs/images/common16/edit.png" />',
                // '</button>',
                // '<% if(o.type=="survey" && o.perm && o.perm.svy) { %>',
                    // '<button class="cardToolbarItem report" >',
                        // '<img title="Report" src="/ujs/images/common16/report.png" />',
                    // '</button>',    
                // '<% } %>',
            // '</div>',
            '<span title="delete survey" class="closeBtn cardCloseBtn" style="<%=o.perm && !o.perm.del ? "display:none" : "" %>" ></span>',
        '</div>'
    ].join('');
    
    return Observable.create({
        init : function(){
            this.cardList = new CardList($('#surveyList'), linkCardTmp);
                       
            this.cardList.$itemAdder.attr('title', lan('app.im.survey.create')); 
            
            this.cardList.$itemAdder.click(function(){
                ujs.ui.Dialog.get(URLDialog , {
                    title : lan('app.im.survey.create'),
                    relType : 'survey'
                });
            });
            
            this.cardList.$itemAdder.tooltipster({
                theme : 'tooltipster-light',
                offsetY : -70
            });
                         
            //删除link
            this.cardList.on('deleteItem', function(cardID){
                var _this = this;        
                bubble.confirm(lan('app.im.survey.delTip'), function(){
                    page.biz.deleteLink(cardID, function(msg){
                        _this.deleteItem(cardID);    
                    }); 
                });
            });
            //编辑link
            this.cardList.on('editItem', function(cardID){                
                ujs.ui.Dialog.get(URLDialog, {       
                    title : lan('app.im.survey.edit'),             
                    mode : 'edit',
                    relType : 'survey',
                    ueid : cardID                        
                });
            });
            this.cardList.on('cardIconClick', function(cardID){
                var obj = page.urlStore.getItem(cardID);
                              
                var previewFrame = new PreviewFrame({
                        id : cardID,
                        src : ujs.browser.loc.addQuery(obj['url'], {isAdmin:obj['creator']['id'] === ujs.util.session.getCurrentUserID() }),
                        title : obj['name'],
                        relType : 'survey',
                        perm : obj['perm'],
                        launchTime : obj['launchTime']
                    });
                    
                sessionList.addItem(obj);
                page.contentCardLayout.addItem(cardID, previewFrame).showItem(cardID);                
                return false;                
            });
            //显示survey报表.
            this.cardList.on('showReport', function(cardID){
                var obj = page.urlStore.getItem(cardID);
                ujs.ui.Dialog.get({   
                    icon : ujs.getRes('images/common32/report.png'),    
                    title : obj['name'],
                    url : obj['url'].replace('mobile', 'report'),
                    width : 800,
                    height : 600                        
                });
            });
        }
    });
})();